<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\policy\model;

use app\cassification\model\ClassificationDictionary;
use plugin\saiadmin\app\model\system\SystemDictData;
use plugin\saiadmin\basic\BaseModel;

/**
 * 政策列表模型
 */
class Policy extends BaseModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'policy_id';

    /**
     * 数据库表名称
     * @var string
     */
    protected $table = 'eb_policy';
    protected $append = ['policy_module_text','policy_category_text'];

    /**
     * 政策/资讯标题 搜索
     */
    public function searchPolicyTitleAttr($query, $value)
    {
        $query->where('policy_title', 'like', '%'.$value.'%');
    }
    public function getPolicyModuleTextAttr($value,$data)
    {
       
        if(isset($data['policy_module'])){
          return    SystemDictData::where('value', $data['policy_module'])->where('type_id',16)->value('label');
        }
        return '';
    }
    public function getPolicyCategoryTextAttr($value,$data)
    {
        if(isset($data['policy_category'])){
          return    ClassificationDictionary::where('dictionary_id', $data['policy_category'])->value('classification_name_zh');
        }
        return '';
    }

}
